home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8729 < prev    next >
Encoding:
Text File  |  1996-08-05  |  7.3 KB  |  249 lines

  1. Path: ix.netcom.com!netnews
  2. From: wells2@ix.netcom.com (wells)
  3. Newsgroups: comp.lang.c++
  4. Subject: need help with functions
  5. Date: Mon, 26 Feb 1996 07:45:23 GMT
  6. Organization: Netcom
  7. Message-ID: <4grqta$mcb@ixnews3.ix.netcom.com>
  8. NNTP-Posting-Host: irv-ca15-23.ix.netcom.com
  9. X-NETCOM-Date: Mon Feb 26 12:27:22 AM PST 1996
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12.  
  13.  
  14.   I am learning c++, I wrote this program and I have a problem with it
  15. that i cant figure out. I am doin this for my class in college. I am
  16. using pass by reference in my functions, and  i have an error that
  17. says something like.... "Get_payment is not suffieciently different
  18. then Get_Payment", or something... I dont understand why.
  19. The program has that error and 4 other warnings, I am not worried
  20. about the warnings, they have to do with my pow(x,x) statement being a
  21. float and not an int. I am just worried about the function error. If
  22. anyone can help I would greatly appreaciate it. And let me know what I
  23. am doing wrong...
  24.  
  25. thanks very much..
  26. edward
  27. wells2@ix.netcom.com
  28.  
  29.  
  30.  
  31.    
  32.    
  33. /////////////////////////////////////////////////////////////////////
  34. // Edward  //
  35.  
  36.  
  37.  
  38. #include <stdio.h>                               // Header.h
  39. #include <iostream.h>                            // Header.h
  40. #include <math.h>                                // Header.h
  41.  
  42.  
  43.  
  44.  
  45. void Loan_Payment();                              // Function Prototype  
  46.  
  47. void Maturity();                                    // Function Prototype    
  48.  
  49. void Get_Payment(float,float,int,float);         // Function Prototype
  50.                  
  51. void Get_Maturity(float,int,float,float,float);  // Function Prototype
  52.                     
  53.                     
  54.                     
  55.                     
  56.                     
  57. void main(void)
  58. {
  59.  
  60.  
  61.     int user_selection;    // variable to hold the menu selection
  62.     
  63.     
  64.     /// Main Menu ////////////////////////////////////////////
  65.     //
  66.     
  67.     cout << "----------- Main Menu ------------\n"; //   
  68.     cout << "\n";                                   //   
  69.     cout << "<1> Loan Payment\n";                   //   print menu on
  70.     cout << "<2> Maturity\n";                       //   the screen.
  71.     cout << "\n";                                   //
  72.     cout << "Enter Your Selection -->";             //   
  73.     
  74.     
  75.     cin >> user_selection;                          //     get user
  76. selection.
  77.                   
  78.                   
  79.     switch (user_selection)
  80.         {                   
  81.         
  82.         
  83.         case '1':             // 
  84.             {                //  If user selected '1', then
  85.             Loan_Payment();  //  go to the funtion "Loan_Payment".
  86.             break;           //
  87.             }                //
  88.         
  89.         
  90.              
  91.         case '2':             //
  92.             {                //     If user selected '2', then 
  93.             Maturity();      //  go to the function "Maturity".
  94.             break;           //
  95.             }                //
  96.         
  97.             
  98.         default:                     //
  99.             {                         // If user selected neither one
  100.             cout << "Bad Selection"; // then end the program.
  101.             }                        //
  102.             
  103.         }  // End of switch
  104.         
  105.         
  106. cout << "End Of Program";    // End the program.
  107. } // End of Program.
  108.             
  109.  
  110.  
  111. ////////////////////////////// Functions
  112. ///////////////////////////////
  113.         
  114.     
  115. void Loan_Payment(void)   // This is the function for figuring loan
  116.                           // payments.  
  117.  
  118.  
  119.     {   
  120.     float loan_amount;        // holds the loan amount.
  121.     float interest_rate;    // holds the interest rate.
  122.     float payment;            // hold the final payment amount.  
  123.     int number_of_payments; // holds the number of payments.
  124.           
  125.     
  126.     
  127.     cout << "Enter the full loan amount ->";      //     input 
  128.     cin >> loan_amount;                           //     data
  129.                                                   //     from
  130.     cout << "\nEnter the interest rate ->";       //     the
  131.     cin >> interest_rate;                         //     user
  132.                                                   //
  133.     cout << "\nEnter the number of payments ->";  //
  134.     cin >> number_of_payments;                    //
  135.                                                              
  136.                                                              
  137.                                                              
  138.     Get_Payment(loan_amount,interest_rate,        //  go calculate payment
  139.                 number_of_payments,payment);      //  in function
  140. Get_Payment.
  141.                
  142.                 
  143.     
  144.     cout << "The Payment is ->";     //  Print the answer to 
  145.     cout << payment;                //  the screen.
  146.     
  147.     return; 
  148.     
  149.     }
  150.     
  151.                          
  152.                          
  153. //////////////////////////////////////////////////////////            
  154.                          
  155.            
  156. void Maturity(void)
  157.     {
  158.     float investment_amount;  // holds the investment amount.
  159.     float interest_rate;      // holds the interest rate.
  160.     float time_in_years;      // holds the length in years.
  161.     float times_compounded;      // holds the times compounded a year.
  162.     float maturity;              // holds the maturity.
  163.     
  164.     
  165.     cout << "\nEnter the investment amount ->";       //
  166.     cin >> investment_amount;                         //
  167.                                                       //
  168.     cout << "\nEnter the interest rate ->";           //  get the input
  169.     cin >> interest_rate;                             //
  170.                                                       //  from the user
  171.     cout << "\nEnter the time in years ->";           //
  172.     cin >> time_in_years;                             //
  173.                                                       //
  174.     cout << "\nHow many times compounded yearly ->";  //
  175.     cin >> times_compounded;                          //
  176.                                                       
  177.                                                       
  178.                                                       
  179.     Get_Maturity(investment_amount,time_in_years,           // get the 
  180.                  times_compounded,maturity,interest_rate);  // maturity.
  181.                  
  182.     cout << "\nThe maturity is ->";     //  output to the
  183.     cout << maturity;                   //  screen.
  184.     
  185.     return;
  186.     }   
  187.     
  188.                         
  189.  
  190. ///////////////////////////////////////////////////////////
  191.  
  192.  
  193.                          
  194.     
  195. void Get_Payment(float &loan_amount,float &interest_rate,int
  196. &number_of_payments,
  197.             float &payment) 
  198.             
  199.     {
  200.             
  201.     float temp1,temp2,temp3,temp4; // temp variables during math.
  202.     
  203.     interest_rate - interest_rate / 1200;                //
  204.     temp1 = (1+interest_rate);                           // do the math 
  205.     temp2 = pow(temp1,number_of_payments)* interest_rate;// for payment.
  206.     temp3 = (1+interest_rate);                           //
  207.     temp4 = pow(temp3,number_of_payments)-1;             //
  208.     payment = ((temp2/temp4)*loan_amount);               //
  209.     return;
  210.     }
  211.     
  212.     
  213.      
  214.      
  215. //////////////////////////////////////////////////////////
  216.  
  217.     
  218.      
  219.                                                    
  220.                  
  221. void Get_Maturity( float &investment_amount,float &time_in_years,
  222.                    float ×_compounded,float &maturity,
  223.                    float &interest_rate)
  224.                    
  225.     {
  226.     float temp1;  // temporary for math function.
  227.     float temp2;  // temporary for math function.
  228.     float temp3;  // temporary for math function.
  229.     
  230.     interest_rate = interest_rate /100;            //
  231.     temp1 = ((interest_rate/times_compounded)+1);  // Do the math to
  232.     temp2 = (time_in_years * times_compounded);    // get the maturity.
  233.     temp3 = pow(temp1,temp2);                      //
  234.     maturity = (temp3 * investment_amount);        //
  235.     
  236.     return;
  237.     }
  238.     
  239.     
  240. /////////////////////////////////////////////////////    
  241.     
  242.                                    
  243.                  
  244.           
  245.           
  246.           
  247.     
  248.  
  249.